package com.bdk.middle.tenant.web;


import com.bdk.middle.common.domain.PageDO;
import com.bdk.middle.common.result.ResultDO;
import com.bdk.middle.common.result.web.ObjectResponse;
import com.bdk.middle.tenant.api.domain.TenantRoleDO;
import com.bdk.middle.tenant.api.query.TenantRoleQueryDO;
import com.bdk.middle.tenant.service.TenantRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户登录表 前端控制器
 * </p>
 *
 * @author Reagan
 * @since 2021-01-23
 */
@Api(tags = "租户角色管理相关接口")
@RestController
@RequestMapping("/tenant_role")
public class TenantRoleController {

    @Autowired
    private TenantRoleService tenantRoleService;
    @ApiOperation(value="租户角色新增", notes="租户角色新增")
    @RequestMapping(value="/add.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse add(@RequestBody TenantRoleDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantRoleService.add(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户角色编辑", notes="租户角色编辑")
    @RequestMapping(value="/edit.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse edit(@RequestBody TenantRoleDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantRoleService.edit(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户角色删除", notes="租户角色删除")
    @RequestMapping(value="/delete.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse delete(@RequestBody TenantRoleDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantRoleService.remove(domain.getId(), null);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户角色详情", notes="租户角色详情")
    @RequestMapping(value="/detail.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse detail(@RequestBody TenantRoleDO domain) {

        ObjectResponse<TenantRoleDO> response = new ObjectResponse();

        ResultDO result = tenantRoleService.get(domain.getId());

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((TenantRoleDO) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }
    @ApiOperation(value="租户角色列表", notes="租户角色列表")
    @RequestMapping(value="/list.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse list(@RequestBody TenantRoleQueryDO domain) {

        ObjectResponse<PageDO<TenantRoleDO>> response = new ObjectResponse();

        ResultDO result = tenantRoleService.find(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((PageDO<TenantRoleDO>) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }

}

